import threading
from Signals.TimerSignal import TimerSignal
import time

#Timer del Round Robin
class Timer(threading.Thread):
    #Se inicia con un quantum para saber cuando expropriar la cpu
    def __init__(self, kernel, quantum):
        threading.Thread.__init__(self)
        self.quantum = quantum 
        self.kernel = kernel
        self.event = threading.Event()
    
    def run(self):
        print("----el timer arranco-----")
        time.sleep(1)
        self.event.wait(self.quantum)
        self.kernel.modoKernel = False
        #print('[kernel.sch] %s'%(self.kernel.modoKernel))
        if not self.kernel.modoKernel and self.kernel.CPU.pc is not None:
            self.kernel.interrupt(TimerSignal(self))
               
    def set(self):
        self.event.set()
        


        

    
    
        
        
    